/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Etbl_Menu;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Mr-aUgust
 */
public class DALtbl_Menu extends BaseConnection{
    CallableStatement clbStm=null;
    ResultSet rs=null;
    public boolean tbl_Menu_add(Etbl_Menu oMenu){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Menu_add_sp(?,?,?,?,?,?)}");
            clbStm.setString("name",oMenu.getName());
            clbStm.setString("groupName",oMenu.getGroupName());
            clbStm.setString("src", oMenu.getSrc());
            clbStm.setString("menuIcon", oMenu.getMenuIcon());
            clbStm.setBoolean("status",oMenu.isStatus());
            clbStm.setBoolean("subMenu",oMenu.isSubMenu());
            clbStm.setInt("priority", oMenu.getPriority());
            return clbStm.execute();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Menu.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    public boolean  tbl_Menu_Edit(Etbl_Menu oMenu){
        try {
            getConnection();
                clbStm=cnn.prepareCall("{call tbl_Menu_update_sp(?,?,?,?,?,?,?)}");
                clbStm.setInt("menuId ",oMenu.getMenuId());
                clbStm.setString("name",oMenu.getName());
                clbStm.setString("groupName",oMenu.getGroupName());
                clbStm.setString("src", oMenu.getSrc());
                clbStm.setString("menuIcon", oMenu.getMenuIcon());
                clbStm.setBoolean("status",oMenu.isStatus());
                clbStm.setBoolean("subMenu",oMenu.isSubMenu());
                clbStm.setInt("priority", oMenu.getPriority());
                return clbStm.execute();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Menu.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    public boolean  tbl_Menu_Delete(int menuId){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Menu_delete_sp(?)}");
            clbStm.setInt("menuId ",menuId);
            return clbStm.execute();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Menu.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    public Etbl_Menu tbl_Menu_getOne(int menuId){
        Etbl_Menu oMenu= new Etbl_Menu();
        try {
            getConnection();
                clbStm=cnn.prepareCall("{call tbl_Menu_Selectone_sp(?)}");
                clbStm.setInt("menuId ",menuId);
                rs=clbStm.executeQuery();
                if(rs.next()){
                  oMenu.setMenuId(menuId);
                  oMenu.setName(rs.getString("name"));
                  oMenu.setMenuIcon(rs.getString("menuIcon"));
                  oMenu.setGroupName(rs.getString("groupName"));
                  oMenu.setSrc(rs.getString("src"));
                  oMenu.setPriority(rs.getInt("priority"));
                  oMenu.setStatus(rs.getBoolean("status"));
                  oMenu.setSubMenu(rs.getBoolean("subMenu"));
                }
                clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Menu.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            return oMenu;
        }
    }
    public ArrayList<Etbl_Menu> tbl_Menu_getAll(){
        ArrayList<Etbl_Menu> arrMenu= new ArrayList<Etbl_Menu>();
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Menu_selectall_sp}");
            rs=clbStm.executeQuery();
            while(rs.next()){
                Etbl_Menu oMenu= new Etbl_Menu();
                oMenu.setMenuId(rs.getInt("menuId"));
                  oMenu.setName(rs.getString("name"));
                  oMenu.setMenuIcon(rs.getString("menuIcon"));
                  oMenu.setGroupName(rs.getString("groupName"));
                  oMenu.setSrc(rs.getString("src"));
                  oMenu.setPriority(rs.getInt("priority"));
                  oMenu.setStatus(rs.getBoolean("status"));
                  oMenu.setSubMenu(rs.getBoolean("subMenu"));
                  arrMenu.add(oMenu);
            }
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Menu.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            return arrMenu;
        }
    }
    public ArrayList<Etbl_Menu> tbl_Menu_getBywhereclause(String Whereclause){
        ArrayList<Etbl_Menu> arrMenu= new ArrayList<Etbl_Menu>();
        try {
            getConnection();
                clbStm=cnn.prepareCall("{call tbl_Menu_selectwhereclause_sp(?)}");
                clbStm.setString("WhereClause", Whereclause);
                rs=clbStm.executeQuery();
                while(rs.next()){
                Etbl_Menu oMenu= new Etbl_Menu();
                oMenu.setMenuId(rs.getInt("menuId"));
                  oMenu.setName(rs.getString("name"));
                  oMenu.setMenuIcon(rs.getString("menuIcon"));
                  oMenu.setGroupName(rs.getString("groupName"));
                  oMenu.setSrc(rs.getString("src"));
                  oMenu.setPriority(rs.getInt("priority"));
                  oMenu.setStatus(rs.getBoolean("status"));
                  oMenu.setSubMenu(rs.getBoolean("subMenu"));
                  arrMenu.add(oMenu);
            }
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Menu.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            return arrMenu;
        }
    }
}
